import Vue from 'vue'
import Router from 'vue-router'
import Login from '../components/Login'
import Layout from '../components/Layout'
import Iframe from '../components/Iframe'
import MyTenant from '../components/MyTenant'
import MyInfo from '../components/MyInfo'

import Member from '../views/Member'
import Org from '../views/Org'
import Role from '../views/Role'
import Menu from '../views/Menu'

// hack router push callback
const originalPush = Router.prototype.push
Router.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(Router)

export default new Router({
  mode: 'history',
  // 页面跳转后，页面是否滚动
  scrollBehavior: () => ({y: 0}),
  routes: [
    {
      path: '/',
      component: Layout,
      children: [
        {path: '/iframe', name: 'iframe', component: Iframe},
        {path: '/myInfo', name: 'myInfo', component: MyInfo},
        {path: '/myTenant', name: 'myTenant', component: MyTenant},
        {path: '/', name: 'org', component: Org},
        {path: '/member', name: 'member', component: Member},
        {path: '/role', name: 'role', component: Role},
        {path: '/menu', name: 'menu', component: Menu}
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    }
  ]
})
